<template>
  <div class="order">
    <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" default-expand-all :highlight-current='true' >
       <span class="custom-tree-node" slot-scope="{ node,data }">
            <span>
                <i :class="data.icon"></i>{{ node.label }}
            </span>              
        </span>
    </el-tree>
  </div>
</template>

<script>

export default {
  name: 'order',
  data () {
    return {
     data: [],

      defaultProps: {
        children: 'children',
        label: 'label'
      }
    
      
    }
  },
  methods:{
    handleNodeClick(data) {
        //console.log(data,'data');
        let _this = this;
        switch(data.label){
          case "设备管理":
            _this.$router.push({
              path:'/manageEquipment'
            });
            break;
          case "用户管理":
            _this.$router.push({
              path:'/manageUser'
            });
            // if(data.level == 1){
            //   _this.$router.push({
            //     path:'/manageUser'
            //   });
            // }
            // else if( data.id != 1){
            //   _this.$router.push({
            //     path:'/manageUsers'
            //   });
            // }
            break;
          case "一级分类管理":
            _this.$router.push({
              path:'/primaryClassification'
            });
            break;
          case "二级分类管理":
            _this.$router.push({
              path:'/secondaryClassification'
            });
            break;
          case "产品管理":
            _this.$router.push({
              path:'/manageProduct'
            });
            break;
          case "角色管理":
            _this.$router.push({
              path:'/manageRole'
            });
            break;
            case "账号管理":
            _this.$router.push({
              path:'/manageUsers'
            });
            break;
            case "联系我们":
            _this.$router.push({
              path:'/contactUs'
            });
            break;


        }
      },
    //获取可见的菜单板块
    getMenu(){
      let _this = this;
      let sessionId = _this.$store.state.id;//获取token
      let api = '/api/admin/menu/find_manager_menus';
      _this.axios.get(api,{
        headers:{
          sessionId,
        }		
      }).then(res=>{
        //console.log('可见的菜单',res);
        let arr = [];
        res.data.data.bussData.forEach(item => {
          arr.push(item.menuName);
        });
        console.log('所有可见菜单数组',arr);
        _this.data = [
            {
              label: '设备管理',
              id:1,
              icon:'iconfont icon-huojianjiqiren',
              children: [{
                label: '设备管理',
                icon:'iconfont',
              }]
            }, 
            {
              label: '用户管理',
              id:1,
              icon:'iconfont icon-ai62',
              children: [{
                label: '用户管理',
                icon:'iconfont',
              }]
            }, 
            {
              label: '分类管理',
              id:1,
              icon:'iconfont icon-login_duanxin',
              children: [{
                label: '一级分类管理',
                icon:'iconfont',
              },
              {
                label: '二级分类管理',
                icon:'iconfont',
              }
              ]
            }, 
            {
              label: '产品管理',
              id:1,
              icon:'iconfont icon-chanpinguanli',
              children: [{
                label: '产品管理',
                icon:'iconfont',
              }]
            }, 
            {
              label: "管理员设置",
              id:1,
              icon:'iconfont icon-guanliyuan',
              children: [{
                label: '角色管理',
                icon:'iconfont',
              },
              {
                label: '账号管理',
                icon:'iconfont',
              }]
            }, 
            {
              label: '联系我们',
              id:1,
              icon:'iconfont icon-dianhua',
              children: [{
                label: '联系我们',
                icon:'iconfont',
              }]
            }, 
        ],
        
        _this.data = _this.data.filter(item=>{
          return arr.indexOf(item.label) > -1
        });
         //console.log('_this.data',_this.data);
         let data = {};
         data.label = _this.data[0].label;
         _this.handleNodeClick(data);
      })
    }
  },
  created(){
    let _this = this;
    _this.getMenu();
  },
  mounted(){
    

    
  }
}
</script>
<style scoped>
@import 'http://at.alicdn.com/t/font_1251791_1mghmrjgepm.css';
/* 整体样式 */
.order{
  height: 100%;
  width: 100%;
  position: relative;
}
/* 所有图标 */
.order>>>.iconfont{
  color: #009688 !important;
  margin-right: 3%;
}
/* 选中行 */
.order>>>.el-tree-node.is-current>.el-tree-node__content{
  background-color: rgba(53, 174, 160, 1) !important;
  color: white;
}

</style>
